﻿using System;
using RootMotion.FinalIK;
using UnityEngine;

namespace RootMotion.Demos
{
	// Token: 0x020000CA RID: 202
	public class Mirror : MonoBehaviour
	{
		// Token: 0x06000606 RID: 1542 RVA: 0x00037EE8 File Offset: 0x000360E8
		public void Start()
		{
			if (!this.target.gameObject.activeInHierarchy)
			{
				return;
			}
			if (this.targetChildren.Length > 0)
			{
				return;
			}
			this.children = base.GetComponentsInChildren<Transform>();
			this.targetChildren = this.target.GetComponentsInChildren<Transform>();
			this.ik = this.target.GetComponent<FullBodyBipedIK>();
			if (this.ik != null)
			{
				IKSolverFullBodyBiped solver = this.ik.solver;
				solver.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Combine(solver.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostFBBIK));
			}
		}

		// Token: 0x06000607 RID: 1543 RVA: 0x00037F88 File Offset: 0x00036188
		public void OnPostFBBIK()
		{
			for (int i = 1; i < this.children.Length; i++)
			{
				for (int j = 1; j < this.targetChildren.Length; j++)
				{
					if (this.children[i].name == this.targetChildren[j].name)
					{
						this.children[i].localPosition = this.targetChildren[j].localPosition;
						this.children[i].localRotation = this.targetChildren[j].localRotation;
						break;
					}
				}
			}
		}

		// Token: 0x06000608 RID: 1544 RVA: 0x00005DBC File Offset: 0x00003FBC
		public void OnDestroy()
		{
			if (this.ik != null)
			{
				IKSolverFullBodyBiped solver = this.ik.solver;
				solver.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(solver.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostFBBIK));
			}
		}

		// Token: 0x04000516 RID: 1302
		public Transform target;

		// Token: 0x04000517 RID: 1303
		public Transform[] children = new Transform[0];

		// Token: 0x04000518 RID: 1304
		public Transform[] targetChildren = new Transform[0];

		// Token: 0x04000519 RID: 1305
		public FullBodyBipedIK ik;
	}
}
